	.TITLE	RND -	RANDOM NUMBER GENERATOR
	.SBTTL	STOLEN FROM FORTRAN-IV-PLUS RUNTIME SYSTEM
	.ENABL	AMA
;
	.GLOBL	INIRND,RND
;
;THIS PACKAGE CONSISTS OF TWO SUBROUTINES:
;
;INIRND-	INIT RANDOM NUMBER GENERATOR
;RND-		GENERATE RANDOM INTEGER
;
;CALLING SEQUENCES-
;
;	CALL INIRND(SEED1,SEED2)
;
;	N=RND(MAX)
;
INIRND:	MOV	@2(R5),LONUM	;PICK UP SEEDS.
	MOV	@4(R5),HINUM
	RTS	PC
;
LONUM:	.WORD	0
HINUM:	.WORD	0
;
RND:	MOV	LONUM,R3	;GET LOW SEED.
	BNE	10$		;IF NE, OK.
	MOV	HINUM,R2	;GET HIGH SEED.
	BNE	20$		;IF NE, OK.
	MOV	#3,R3		;BOTH ZERO, RESEED WITH 2**16+3.
	MOV	#1,R2
	BR	20$
;
10$:	MOV	HINUM,R2	;SEED NOW IN R2:R3.
20$:	MOV	R3,R0		;MULTIPLY BY 2**16 (LEFT SHIFT 16).
	CLR	R1
	ADD	R3,R1		;+3 (ADD IN 3 TIMES).
	ADC	R0
	ADD	R2,R0
	ADD	R3,R1
	ADC	R0
	ADD	R2,R0
	ADD	R3,R1
	ADC	R0
	ADD	R2,R0
	MOV	R1,LONUM	;SAVE RESULTS.
	MOV	R0,HINUM
;
	MOV	R0,R1
	CLR	R0
	MOV	#16.,R2		;PREPARE FOR DIVIDE.
	ASL	R1
30$:	ROL	R0		;ROTATE DIVIDEND.
	CMP	@2(R5),R0	;SUBTRACT WORK?
	BHI	40$		;IF HI, NO.
	SUB	@2(R5),R0
	SEC
40$:	ROL	R1		;ONWARD.
	DEC	R2
	BNE	30$
	RTS	PC
;
	.END
